/**
 * å¤éæ¡å¨é
 * @param window
 * @param jQuery
 */
!function (window, $) {
	if (!window || !$) {
		return
	}
	
	var _itemClass = ".item-checkbox";
	var _allClass = ".all-checkbox";
	var _checkAllClass = ".check-all";
	
	$.extend({
		
		clickCheckItem: function (that) {
			stopPropagation();
			$(_checkAllClass).attr("checked", false);
			if ($(that).is(":checked")) {
				if ($(_itemClass + ":checked").length == $(_itemClass).length) {
					$(_allClass).prop("checked", true);
					//added_bycjw
					$(_checkAllClass).prop("checked", true);
				} else {
					$(_allClass).prop("checked", false);
					$(_checkAllClass).prop("checked", false);
				}
				//给checkbox所在行增加样式
				$(that).parents("tr").eq(0).addClass("chooseRow");
				
			} else {
				$(_allClass).prop("checked", false);
				$(_checkAllClass).prop("checked", false);
				//给checkbox所在行取消样式
				$(that).parents("tr").eq(0).removeClass("chooseRow");
			}
		},
		
		clickAllCheck: function (that) {
			if ($(that).is(":checked")) {
				$(_itemClass).prop("checked", true);
				//给checkbox所在行增加样式
				$(_itemClass).each(function () {
					$(this).parents("tr").eq(0).addClass("chooseRow");
				});
			} else {
				$(_itemClass).prop("checked", false);
				//给checkbox所在行取消样式
				$(_itemClass).each(function () {
					$(this).parents("tr").eq(0).removeClass("chooseRow");
				});
			}
		},
		
		getCheckIds: function () {
			var ids = "";
			var i = 0;
			$(_itemClass).each(function (index, ele) {
				if ($(this).is(":checked")) {
					if (i == 0) {
						ids += $(this).data("id");
					} else {
						ids += "," + $(this).data("id");
					}
					i++;
				}
			})
			return ids;
		},
	})
	
	//é»æ­¢åç´ åä¸åæ³¡
	function stopPropagation(e) {
		e = e || window.event;
		if (e.stopPropagation) { //W3Cé»æ­¢åæ³¡æ¹æ³
			e.stopPropagation();
		} else {
			e.cancelBubble = true; //IEé»æ­¢åæ³¡æ¹æ³
		}
	}
	
	
}(window, jQuery)